package cn.bgs.service.Impl;

import cn.bgs.mapper.CellMapper;
import cn.bgs.pojo.CellIntermediate;
import cn.bgs.pojo.UserVo;
import cn.bgs.service.CellService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CellServiceImpl implements CellService {
    @Autowired
    private CellMapper cellMapper;
    @Override
    public PageInfo<CellIntermediate> findcell(String communityId,String state, String identity, Integer pagesize, Integer pagenow) {
        if(pagenow==null){
            pagenow=1;
        }
        if(pagesize==null){
            pagesize=10;
        }
        PageHelper.startPage(pagenow,pagesize);
        List<CellIntermediate> findcell = cellMapper.findcell(communityId,state,identity);
        PageInfo<CellIntermediate> a = new PageInfo<>(findcell);
        return a;
    }

    @Override
    public void del(Integer id) {
        cellMapper.del(id);
    }

    @Override
    public List<CellIntermediate> load(Integer id) {
        List<CellIntermediate> cellIntermediates = cellMapper.load(id);
        return cellIntermediates;
    }

    @Override
    public void adduser(UserVo forms) {
        cellMapper.adduser(forms);
        String middleId = forms.getMiddleId();
        Integer userId = forms.getUserId();
        cellMapper.addcell(userId,middleId);
    }

    @Override
    public void updatestate(CellIntermediate forms) {
        cellMapper.updatestate(forms);
    }
}